#
# @lc app=leetcode.cn id=111 lang=python3
#
# [111] 二叉树的最小深度
#

# @lc code=start
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def minDepth(self, root: TreeNode) -> int:
        return self.minD(root)

    def minD(self,treeNode):
        if treeNode == None: 
            return 0
        elif treeNode.left == None and treeNode.right == None:
            return 1
        
        minDepth = 10**5
        if treeNode.left != None:
            minDepth = min(self.minD(treeNode.left), minDepth)
        if treeNode.right != None:
            minDepth = min(self.minD(treeNode.right), minDepth) 
            
        return minDepth + 1
        
            
# @lc code=end

